<template>
  <section class="content">
    <div class="goods_info">
      <section class="goods">
        <section class="good_img">
          <img :src="auction_info.pic_url+'180x180'" width="80" heigth="80" v-if="auction_info.is_compress==1">
          <img :src="auction_info.pic_url" width="80" heigth="80" v-else>
        </section>
        <section class="g-flex">
          <p class="title">{{auction_info.item_title}}</p>
          <p class="user_info">
            <span class="degree">出价次数：<i>{{auction_info.bidding_turn}}</i></span>
            <span class="num">竞拍人数：<i>{{auction_info.bidding_user_count}}</i></span>
          </p>
        </section>
      </section>
      <section class="active_time">
        <goods-activity
          actType="PaiM"
          :isShow="false"
          :isPaiMStatus="auction_info.active_status"
          actMsg="距结束还剩"
          :actEndTime="auction_info.round_countdown"></goods-activity>
        <div class="time_r">
          <span class="now_round">第{{auction_info.turn}}轮/</span><span>共{{auction_info.active_turn}}轮</span>
        </div>
      </section>
    </div>
    <div class="auction_info">
      <ul class="auction_ul">
        <li v-for="(bidding_vo,index) in auction_info.auction_bidding" :key="index">
            <div class="user_pay_info">
                <span v-if="index == 0">领先</span>
                <span v-else>出局</span>
            </div>
            <div class="auction_time">
              <p>{{bidding_vo.mobile}} 出价 <i>&yen;{{bidding_vo.money}}</i></p>
              <div class="time-box">
                <span class="time">
                  <i></i>
                  <em>{{bidding_vo.create_time}}</em>
                </span>
                <count-down v-if="index == 0" class="count_down" :actEndTime="auction_info.delay_countdown"></count-down>
              </div>
            </div>
        </li>
      </ul>
    </div>
    <div class="auction_info_content">
      <p>拍卖结束后, 请点击<span @click="auctionDetails">前往查看></span>拍卖详情!</p>
    </div>
    <div class="auction_pay">
      <p class="pay_l">
        <span class="num">
          <i class="min" @click="min()">-</i>
          <em class="bidding_money">{{auctionBiddingMoney}}</em>
          <i class="man" @click="man()">+</i>
        </span>
        <span class="info">
          <i>加价幅度</i>
          <em>&yen;{{auction_info.fare_increase}}</em>
        </span>
      </p>
      <p class="pay_r" @click="showDonationClick">出价</p>
    </div>
    <!-- 出价金额弹框 -->
    <!-- <div class="shade"></div> -->
    <van-dialog
			v-model="showDonation"
			title="出价金额"
			show-cancel-button
			@confirm='confirmDonation'
      confirm-button-text="确定"
			class="common-confirm"
			@close="hideDonation"
		>
			<section class="box_content">
          <p class="price">
            <input type="tel" class="pay_price" v-model="auctionBiddingMoney"/>
          </p>
          <p class="price_info"><i></i><span>您当前的出价金额暂时领先，确认出价后请密切关注出价动态</span></p>
      </section>
		</van-dialog>
    <!-- 活动结束弹窗 -->
  </section> 
</template>

<script>
import { getAuctionLobby, bidDingData } from '@/api/activity/activityApi'
import goodsActivity from '@/views/item/components/goodsActivity'
import countDown from './components/countDown'
import Vue from 'vue'
var interval = null
var refresh = null
export default Vue.extend({
  components: {
    // Payment
    goodsActivity,
    countDown
  },
  data() {
    return {
      paymentWay: '',
      showDonation: false,
      auction_info: {},
      defalutMoney: 0, // 原始保证金
      auctionBiddingMoney: 0, // 现在的保证金
      fareIncrease: 0, // 加价幅度,
      countDownList: ''
    }
  },
  created() {
    // 每5秒刷新
    refresh = setInterval(() => {
      this.getAuctionLobby()
    }, 5000)
    this.getAuctionLobby()
  },
  beforeDestroy() {
    // console.log('aaa')
    clearInterval(refresh)
    clearInterval(interval)
  },
  methods: {
    // 加减保证金
    min() {
      if (this.auctionBiddingMoney < this.defalutMoney + this.fareIncrease) {
        return false
      }
      this.auctionBiddingMoney = (parseFloat(this.auctionBiddingMoney - this.fareIncrease)).toFixed(2)
    },
    man() {
      this.auctionBiddingMoney = (parseFloat(this.auctionBiddingMoney + this.fareIncrease)).toFixed(2)
    },
    confirmDonation() {
      this.hideDonation()
      const query = this.$route.query
      const data = {
        item_auction_id: query.id,
        auction_turn_id: this.auction_info.auction_turn_id,
        money: this.auctionBiddingMoney
      }
      // 请求接口
      bidDingData(data).then(res => {
        if (res.status == 1) {
          this.getAuctionLobby()
        } else {
          this.$Error(res.msg)
        }
      })
    },
    showDonationClick() {
      this.showDonation = true
    },
    hideDonation() {
      this.showDonation = false
      this.auctionBiddingMoney = this.defalutMoney
    },
    auctionDetails() {
      clearInterval(refresh)
      clearInterval(interval)
      this.Jump('myAuction');
    },
    Jump(url, data) {
      this.$JumpPath(this, url, data)
    },
    // 缴纳保证金
    getAuctionLobby() {
      const query = this.$route.query
      const params = {
        item_auction_id: query.id
      }
      this.$loadingWrap.show()
      getAuctionLobby(params).then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          this.auction_info = res.data
          this.defalutMoney = Number(this.auction_info.auction_bidding_money)
          this.auctionBiddingMoney = this.defalutMoney
          this.fareIncrease = Number(this.auction_info.fare_increase)
        } else {
          this.$Error(res.msg)
        }
      })
    },

    // 本轮倒计时

    /**
       * 补全小于10的
       */
    timeFormat(param) {
      return param < 10 ? '0' + param : param
    },
    /**
       * 倒计时
       */
    countDown(it) {
      interval = setInterval(() => {
        // 获取当前时间，同时得到活动结束时间数组
        const newTime = new Date().getTime()
        // 对结束时间进行处理渲染到页面
        const endTime = new Date(it).getTime()
        let obj = null
        // 如果活动未结束，对时间进行处理
        if (endTime - newTime > 0) {
          const time = (endTime - newTime) / 1000
          // 获取天、时、分、秒
          const day = parseInt(time / (60 * 60 * 24))
          const hou = parseInt(time % (60 * 60 * 24) / 3600)
          const min = parseInt(time % (60 * 60 * 24) % 3600 / 60)
          const sec = parseInt(time % (60 * 60 * 24) % 3600 % 60)
          obj = {
            day: this.timeFormat(day),
            hou: this.timeFormat(hou),
            min: this.timeFormat(min),
            sec: this.timeFormat(sec)
          }
        } else { // 活动已结束，全部设置为'00'
          obj = {
            day: '00',
            hou: '00',
            min: '00',
            sec: '00'
          }
          clearInterval(interval)
        }
        this.countDownList = `<span class="num">${obj.min}</span>分<span class="num">${obj.sec}</span>秒`
      }, 1000)
    }
  }
})
</script>

<style lang="scss">
@import 'src/styles/mixin';
.content{
  .goods_info{
    .goods{
			overflow: hidden;
			background: #fff;
			padding:30px;
      display: flex;
      .good_img{
        width:160px;
        height:160px;
        border-radius:10px;
        overflow: hidden;
        img{
          width: 100%;
        }
      }
      .g-flex{
        padding: 10px 0;
        flex: 1;
        margin-left: 15px;
        display: flex;
        flex-flow: column;
        justify-content: space-between;
        .title{
          color:rgba(51,51,51,1);
          font-weight:bold;
          @include lineClamp(24px,30px,2)
        }
        .user_info{
          font-size: 24px;
          color: #666666;
          span{
            margin-right: 34px;
          }
          i{
            color: #F30C23;
          }
        }
      }
    }
    .active_time{
      position: relative;
      .time_r{
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        left: 30px;
        font-size: 28px;
        color: #fff;
        font-weight: bold;
      }
    }
  }
  .auction_info{
    .auction_ul{
      padding: 30px;
      li{
        background: #fff;
        margin-bottom: 20px;
        display: flex;
        &:first-child{
          .user_pay_info{
            background: #FFF0F1;
            color: #F21228;
          }
        }
        .user_pay_info{
          width: 120px;
          line-height: 120px;
          text-align: center;
          background: #E6E6E6;
          font-size: 28px;
          color: #999999;
        }
        .auction_time{
          flex: 1;
          display: flex;
          padding: 27px 36px;
          flex-flow: column;
          justify-content: space-between;
          p{
            font-size: 28px;
            i{
              color: #F21228;
            }
          }
          .time-box{
            .time{
              display:inline-block;
              color: #999999;
              margin-right: 20px;
            }
            .count_down{
              display:inline-block;
              .time-out{
                display:inline-block;
              }
            }
          }
          
        }
      }
    }
  }
  .auction_info_content{
    width:750px;
    line-height:90px;
    background:rgba(255,245,235,1);
    position: fixed;
    bottom: 98px;
    p{
      text-align: center;
      font-size: 28px;
      span{
        color: #F21228;
        text-decoration: underline;
        margin: 0 5px;
      }
    }
  }
  .auction_pay{
    width: 100%;
    background: #fff;
    position:fixed;
    bottom:0px;
    left: 0px;
    height:98px;
    line-height: 98px;
    z-index: 999;
    display: flex;
    padding: 11px 25px;
    .pay_l{
      flex:1;
      position:relative;
      padding: 4px 0;
      display: flex;
      .num{
        text-align: center;
        border-right: 1px solid #EDEDED ;
        padding-right: 25px;
        display: flex;
        align-items: center;
        i{
          width: 40px;
          height:30px;
          // color:#E5E5E5;
          font-size: 36px;
          font-weight: bold;
          display: block;
          text-align: center;
          line-height: 30px;
        }
        em{
          display: block;
          width:106px;
          line-height:50px;
          background:rgba(247,247,247,1);
          border-radius:4px;
        }
        .min{
          margin-right: 15px;
        }
        .man{
          margin-left: 15px;
        }
      }
      .info{
        padding-left: 55px;
        display: flex;
        flex-flow: column;
        justify-content: space-around;
        line-height: initial;
        i{
          
        }
        em{
          font-size: 26px;
          color: #F21228;
          font-weight: bold;
        }
      }
    }
    .pay_r{
      width:188px;
      line-height:76px;
      text-align: center;
      color: #fff;
      border-radius:76px ;
      font-size: 32px;
      @include gradient(left,rgba(233,1,4,1),rgba(254,27,73,1));
    }
  }
  .box_content{
    padding: 20px 57px;
    .price{ 
      input{
        width: 100%;
        height:106px;
        background:rgba(255,240,241,1);
        border-radius:6px;
        text-align: center;
        font-size: 50px;
        color: #F21228;
        padding: 25px 0;
      }
    }
    .price_info{
      padding: 15px 0 ;
      font-size: 24px;
      line-height: 36px;
    }
  }
}
</style>